import React from "react";
import LeftArrow from "../LeftArraw";
import style from "./style.module.scss";
import { useNavigate } from "react-router-dom";
import { getHttp, putHttpParams } from "../../../../api";
import { useAppSelector } from "../../../../store/hooks";
import { useSetState, useRequest } from "ahooks";
import { OperateSuccess } from "../../../../components";

// 礼物列表接口

// 送礼物接口
interface CurrentInquiryRecordHeader {
  userId: number;
  sessionId: string;
}

interface CurrentInquiryRecordParams {
  inquiryRecordId: number;
  giftId: number;
}

// 定义问诊信息接口
interface IConsultationInfo {
  status: string;
  message: string;
}

const Index: React.FC = () => {
  //获取礼物列表
  const findGiftLists = () => getHttp("/health/user/inquiry/v1/findGiftList");
  const { data: findGiftList = [] } = useRequest(async () => {
    const resp = await findGiftLists();
    return resp.result;
  });

  const userId = useAppSelector((state) => state.user.userInfo.userId);
  const sessionId = useAppSelector((state) => state.user.userInfo.sessionId);
  const recordId = useAppSelector((state) => state.doctor.recordId);
  const navigate = useNavigate();
  console.log(recordId);
  const [inquiryParams, setInquiryParams] =
    useSetState<CurrentInquiryRecordHeader>({
      userId: userId,
      sessionId: sessionId,
    });

  const handleGoBack = () => {
    navigate("/consultation/my/history");
  };
//点击调用送礼物接口
  const getGift = async (id: number) => {
    const params: CurrentInquiryRecordParams = {
      inquiryRecordId: recordId, //***************问题在这里报错信息为Required int parameter 'inquiryRecordId' is not present**************************** */
      giftId: id,
    };
    const resp = await getCurrentInquiryRecord(params);
    console.log(resp);
  };
  /*************************************调用送礼物接口********************************************************/
  const getCurrentInquiryRecord = async (
    params: CurrentInquiryRecordParams
  ) => {
    const resp = await putHttpParams(
      "/health/user/inquiry/verify/v1/handselGift", //***************这里完全按照文档但是报错******************* */
      params, //请求载荷inquiryRecordId：6145，giftId：1001
      inquiryParams
    );
    return resp.result;
  };

  return (
    <div>
      <LeftArrow title="评价成功" />
      <OperateSuccess
        text={
          <div className={style["res-text"]}>
            <span>评价成功,感谢您！ </span>
          </div>
        }
      />
      <h3 className={style["h3"]}>
        如果您遇到的问题得到解决?给个礼物鼓励一下吧～
      </h3>
      {findGiftList.length > 0 &&
        findGiftList.map((item, indx) => {
          return (
            <div className={style["div"]} key={indx}>
              <dl>
                <dt>
                  <img src={item.pic} alt="" />
                </dt>
                <dd>
                  <div>
                    <h4>{item.name}</h4>
                    <p>{item.worth}H币</p>
                  </div>
                  <button onClick={() => getGift(item.id)}>立即赠送</button>
                </dd>
              </dl>
            </div>
          );
        })}

      <div className={style["btndiv"]}>
        <button className={style.btn} onClick={handleGoBack}>
          返回
        </button>
      </div>
    </div>
  );
};

export default Index;
